package com.dong.dynamicProgramming;

/**
 * @author dcz
 * @classname Test
 * @description TODO
 * @date 2022/4/29 9:04
 */
public class Test {
    public static void main(String[] args) {
        int[] prices = {7,6,4,3,1};
        int i = maxProfit(prices);
        System.out.println(i);
    }

    public static int maxProfit(int[] prices) {
        int len = prices.length;
        //第i天持有股票获取最多现金 0不持有  1持有
        int[][] dp = new int[len][2];
        dp[0][0] = 0;
        dp[0][1] = -prices[0];
        for (int i = 0; i < len; i++) {
            dp[i][0] = Math.max(dp[i-1][0],dp[i-1][1]-prices[i]);
            dp[i][1] = Math.max(dp[i-1][0]-prices[i],dp[i-1][1]);
        }
        return dp[len-1][0];

    }
}
